<?php
/**
 * Talents come from diligence, and knowledge is gained by accumulation.
 *
 * @author: 晋<657306123@qq.com>
 * @date: 2019/8/5 23:23
 */

use Xin\Filesystem\Factory;

require_once '../vendor/autoload.php';
$config = require_once './config.php';

// 获取七牛云对象存储实现类
//$storage = Factory::qiniu($config['qiniu']);

// 获取阿里云云对象存储实现类
$storage = Factory::aliyun($config['aliyun']);

// 创建文件夹
var_dump("创建文件夹：");
$result = $storage->createDir('test');
var_dump($result ? "创建成功" : "创建失败");
var_dump($storage->getLastError());

// 上传文件
var_dump("上传文件：");
$result = $storage->putStream('test-1.jpg', fopen('./001.png', 'r'));
var_dump($result ? "上传成功" : "上传失败");
var_dump($storage->getLastError());

// 上传字符串
var_dump("上传内容：");
$result = $storage->put('test-2.txt', 'hello world');
var_dump($result ? "上传成功" : "上传失败");
var_dump($storage->getLastError());

// 重命名文件
var_dump("重命名文件：");
$result = $storage->rename('test-2.txt', 'helloworld.txt');
var_dump('rename file '.($result ? 'success' : 'fail'));
var_dump($storage->getLastError());

// 文件详细信息
var_dump("文件详细信息：");
$result = $storage->getMetadata('test-1.jpg');
var_dump($result);
var_dump($storage->getLastError());

// 删除文件
var_dump("删除文件：");
$storage->delete('helloworld.txt');
var_dump('delete file ok.');
var_dump($storage->getLastError());

// 文件列表
var_dump("文件列表：");
$result = $storage->listContents();
var_dump($result);
//var_dump($storage->getLastError());
